/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.UserDao;
import dao.UserDaoImpl;
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author takamflore
 */
public class LoginServlet extends HttpServlet {

 private static final long serialVersionUID = 1L;
 @EJB
 UserDao userDao;
 String forward="";
 
 public LoginServlet() {
        super();
        userDao = new UserDaoImpl();
    }
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action= request.getParameter("action");
        if(action.equalsIgnoreCase("Sign in")){
           // request.login(request.getParameter("email"), request.getParameter("password"));//realm
            String email= request.getParameter("email");
            String pas= request.getParameter("password");
            if(userDao.checkUserLogin(email, pas)== 1){
                HttpSession session = request.getSession();
                session.setAttribute("email", "password");
            forward="/welcomePage.jsp";
            }else{
                forward="/Login.jsp";
            }    
        }else{
            forward="/Registration.jsp";
        }
         RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
